﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using NBlog.Web.Application.Infrastructure;
using NBlog.Web.Application.Service.Entity;

namespace NBlog.Web.Controllers
{
    public partial class EntryController
    {
        public class EditModel : LayoutModel
        {
            public string Slug { get; set; }

            [DisplayName("Slug")]
            [Required(ErrorMessage = "Please supply a slug for this post")]
            [RegularExpression("^[a-zA-Z0-9-]+$", ErrorMessage = "That's not a valid slug. Only letters, numbers and hypens are allowed.")]
            public string NewSlug { get; set; }

            [AllowHtml]
            [Required(ErrorMessage = "Please enter the date this post was created.")]
            public string Date { get; set; }

            [AllowHtml]
            [Required(ErrorMessage = "Please enter the title of this post.")]
            public string Title { get; set; }

            [AllowHtml]
            [Required(ErrorMessage = "Please enter some content.")]
            public string Markdown { get; set; }

            [DisplayName("Enable code syntax highlighting")]
            public bool IsCodePrettified { get; set; }
        }

        public class PageModel : EntityModel
        {
            public string Html { get; private set; }

            public PageModel(PageEntity pageEntity)
            {
                Initialize(pageEntity);

                var markdown = new MarkdownSharp.Markdown();
                var html = markdown.Transform(pageEntity.Markdown);
                Html = html;
            }
        }

        public class ArticleModel : PageModel
        {
            public ArticleModel(ArticleEntity articleEntity) : base(articleEntity)
            {
                Products = articleEntity.Products;
            }

            public Product[] Products { get; private set; }
        }

        public class ReviewModel : EntityModel
        {
            public string Html { get; private set; }

            public ReviewModel(ReviewEntity reviewEntity)
            {
                Initialize(reviewEntity);

                var markdown = new MarkdownSharp.Markdown();
                var html = markdown.Transform(reviewEntity.Markdown);
                Html = html;
            }
        }
    }

    public class EntityModel : LayoutModel
    {
        public string Slug { get; set; }
        public string Title { get; set; }

        protected void Initialize(BaseEntity baseEntity)
        {
            Slug = baseEntity.Slug;
            Title = baseEntity.Title;
            Meta = new MetaInfoModel(baseEntity.MetaTitle, baseEntity.MetaKeywords, baseEntity.MetaDescription);
        }
    }

    public class MetaInfoModel
    {
        public string Title { get; internal set; }
        public string Keywords { get; internal set; }
        public string Description { get; internal set; }

        public MetaInfoModel(string title, string keywords, string description)
        {
            Title = title;
            Keywords = keywords;
            Description = description;
        }
    }

    public class Product
    {
        public string Id { get; set; }
        public string Image { get; set; }
        public string ListPrice { get; set; }
        public string Price { get; set; }
        public string Text { get; set; }
        public string Title { get; set; }
    }
}